layui.config({
    base : "/dhjdglxt/modules/util/"//自定义加载的模块
}).extend({
    formSelects: 'formSelects-v4.min'
}).use(['form','layer','jquery','layedit','laydate','laypage','table','commUtil','element','treetable',"formSelects"],function(){
    var form = layui.form,
        layer = parent.layer === undefined ? layui.layer : parent.layer,
        laypage = layui.laypage,
        layedit = layui.layedit,
        laydate = layui.laydate,
        $ = layui.jquery;
    var table = layui.table;
    var commUtil = layui.commUtil;
    var element = layui.element;
    var treetable = layui.treetable;//很重要
    var formSelects = layui.formSelects;
    var min="";
    var max="";
    $.ajax({
    	type: 'GET',
    	url: basePath + '/service/cxtj/getAllUseAirPlan',
    	dataType: 'json',
    	async:false,
    	success: function(data) {
    		if(data.length>0) {
    			for (var i = 0; i < data.length; i++) {
					$("#s_sign").append('<option value=\"'+data[i].sign+'\">'+data[i].sign+'</option>')
				}
    		}
    		formSelects.render('s_sign');
    	}
    })
    $.ajax({
    	type: 'GET',
    	url: basePath + '/service/exchangerate/getMinMax',
    	dataType: 'json',
    	async:false,
    	success: function(data) {
    		min = data.min;
    		max = data.max;
    	}
    })
    
    laydate.render({
	    elem: '#s_starnf',
	    trigger: 'click',
	    min:min,
	    max:max,
	    type:'date'
	    ,value: new Date()
	    ,ready: function(date){
	    	var date = date.year+"-"+date.month
	    	 $.ajax({
	    	    	type: 'GET',
	    	    	url: basePath + '/service/exchangerate/getUseDate/'+date,
	    	    	dataType: 'json',
	    	    	async:false,
	    	    	success: function(data) {
	    	    		var use = data.usedate
	    	    		var td = $(".layui-laydate-content").find('td');
	    	    		for(var i =0;i<td.length;i++){
	    	    			var layYmd = $($(".layui-laydate-content").find('td')[i]).attr("lay-ymd");
	    	    			var lay = layYmd.split("-"); 
	    	    			var m = lay[1];
	    	    			var d = lay[2];
	    	    			if(parseInt(lay[1])<10){
	    	    				m = "0"+lay[1];
	    	    			}
	    	    			if(parseInt(lay[2])<10){
	    	    				d = "0"+lay[2];
	    	    			}
	    	    			layYmd = lay[0]+"-"+m+"-"+d;
	    	    			if(use.indexOf(layYmd)<0){
	    	    				$($(".layui-laydate-content").find('td')[i]).attr("style","cursor: not-allowed;color:#d2d2d2");
	    	    		    	$($(".layui-laydate-content").find('td')[i]).addClass('ng-laydate-disabled');
	    	    			}else{
	    	    				$($(".layui-laydate-content").find('td')[i]).attr("style","");
	    	    			}
	    	    		}
	    	    	}
	    	    })
	    	
	      },change: function(value, date, endDate){
	    	  var date = date.year+"-"+date.month
		    	 $.ajax({
		    	    	type: 'GET',
		    	    	url: basePath + '/service/exchangerate/getUseDate/'+date,
		    	    	dataType: 'json',
		    	    	async:false,
		    	    	success: function(data) {
		    	    		var use = data.usedate
		    	    		var td = $(".layui-laydate-content").find('td');
		    	    		for(var i =0;i<td.length;i++){
		    	    			var layYmd = $($(".layui-laydate-content").find('td')[i]).attr("lay-ymd");
		    	    			var lay = layYmd.split("-"); 
		    	    			var m = lay[1];
		    	    			var d = lay[2];
		    	    			if(parseInt(lay[1])<10){
		    	    				m = "0"+lay[1];
		    	    			}
		    	    			if(parseInt(lay[2])<10){
		    	    				d = "0"+lay[2];
		    	    			}
		    	    			layYmd = lay[0]+"-"+m+"-"+d;
		    	    			if(use.indexOf(layYmd)<0){
		    	    				$($(".layui-laydate-content").find('td')[i]).attr("style","cursor: not-allowed;color:#d2d2d2");
		    	    		    	$($(".layui-laydate-content").find('td')[i]).addClass('ng-laydate-disabled');
		    	    			}else{
		    	    				$($(".layui-laydate-content").find('td')[i]).attr("style","");
		    	    			}
		    	    		}
		    	    	}
		    	    })
	    	  }
	    
	});
    laydate.render({
	    elem: '#s_endnf',
	    trigger: 'click',
	    min:min,
	    max:max,
	    type:'date'
	    ,value: new Date() ,ready: function(date){
	    	var date = date.year+"-"+date.month
	    	 $.ajax({
	    	    	type: 'GET',
	    	    	url: basePath + '/service/exchangerate/getUseDate/'+date,
	    	    	dataType: 'json',
	    	    	async:false,
	    	    	success: function(data) {
	    	    		var use = data.usedate
	    	    		var td = $(".layui-laydate-content").find('td');
	    	    		for(var i =0;i<td.length;i++){
	    	    			var layYmd = $($(".layui-laydate-content").find('td')[i]).attr("lay-ymd");
	    	    			var lay = layYmd.split("-"); 
	    	    			var m = lay[1];
	    	    			var d = lay[2];
	    	    			if(parseInt(lay[1])<10){
	    	    				m = "0"+lay[1];
	    	    			}
	    	    			if(parseInt(lay[2])<10){
	    	    				d = "0"+lay[2];
	    	    			}
	    	    			layYmd = lay[0]+"-"+m+"-"+d;
	    	    			if(use.indexOf(layYmd)<0){
	    	    				$($(".layui-laydate-content").find('td')[i]).attr("style","cursor: not-allowed;color:#d2d2d2");
	    	    		    	$($(".layui-laydate-content").find('td')[i]).addClass('ng-laydate-disabled');
	    	    			}else{
	    	    				$($(".layui-laydate-content").find('td')[i]).attr("style","");
	    	    			}
	    	    		}
	    	    	}
	    	    })
	    	
	      },change: function(value, date, endDate){
	    	  var date = date.year+"-"+date.month
		    	 $.ajax({
		    	    	type: 'GET',
		    	    	url: basePath + '/service/exchangerate/getUseDate/'+date,
		    	    	dataType: 'json',
		    	    	async:false,
		    	    	success: function(data) {
		    	    		var use = data.usedate
		    	    		var td = $(".layui-laydate-content").find('td');
		    	    		for(var i =0;i<td.length;i++){
		    	    			var layYmd = $($(".layui-laydate-content").find('td')[i]).attr("lay-ymd");
		    	    			var lay = layYmd.split("-"); 
		    	    			var m = lay[1];
		    	    			var d = lay[2];
		    	    			if(parseInt(lay[1])<10){
		    	    				m = "0"+lay[1];
		    	    			}
		    	    			if(parseInt(lay[2])<10){
		    	    				d = "0"+lay[2];
		    	    			}
		    	    			layYmd = lay[0]+"-"+m+"-"+d;
		    	    			if(use.indexOf(layYmd)<0){
		    	    				$($(".layui-laydate-content").find('td')[i]).attr("style","cursor: not-allowed;color:#d2d2d2");
		    	    		    	$($(".layui-laydate-content").find('td')[i]).addClass('ng-laydate-disabled');
		    	    			}else{
		    	    				$($(".layui-laydate-content").find('td')[i]).attr("style","");
		    	    			}
		    	    		}
		    	    	}
		    	    })
	    	  }
	    
	});
    
    var yshead = [
    	{type:'numbers',title: '序号',align:'center'}
    	,{field:'sign',title: '国籍标志和登记标志',align:'center'}
    	,{field:'zjzfqj',title: '租金支付期间',align:'center'}
    	,{field:'htMoney', title: '每期支付租金',align:'center',templet:function(d){
    		if(d.htMoney==null||d.htMoney==''||typeof(d.htMoney)=='undefined'){
    			return '';
    		}else{
    			return '<div style="text-align:right;">'+d.htMoney+'</div> ';
    		}
    	}}
    ];
    
    
    
    
    $(".onQuery").click(function(){
        onQuery();
    })
    var tables ;
    function onQuery(){
    	var s_starnf = $("#s_starnf").val();
    	var s_endnf = $("#s_endnf").val();
    	var s_sign = layui.formSelects.value('s_sign', 'val');
    	if(s_starnf == '' || s_starnf == undefined || s_endnf == '' || s_endnf == undefined ){
    		layer.msg("请选择两个对比时间");
    		return;
    	}
    	$.ajax({
    		type: "GET",
    		url: basePath + '/service/exchangerate/getTwoByTwoFbDate/'+s_starnf+'/'+s_endnf,
    		async:false,
    	    dataType: "json",
    	    success: function(data){
    	    	if(data.code == 200){
    	    		var headerAppend = [];
    	    		headerAppend.push(
	    				{
	    	    			field:'qhl', 
	    	    			title: data.dateks.fbDate+'美元汇率：'+((data.dateks.bankConversionPri/100)+"").substr(0,6),
	    	    			align:'center',templet:function(d){
	    	    				if(d.qhl==null||d.qhl==''||typeof(d.qhl)=='undefined'){
	    	    	    			return '';
	    	    	    		}else{
	    	    	    			return '<div style="text-align:right;">'+d.qhl+'</div> '
	    	    	    		}
	    	    	    	}
	    				},{
	    	    			field:'hhl', 
	    	    			title: data.datejs.fbDate+'美元汇率：'+((data.datejs.bankConversionPri/100)+"").substr(0,6),
	    	    			align:'center',templet:function(d){
	    	    				if(d.hhl==null||d.hhl==''||typeof(d.hhl)=='undefined'){
	    	    	    			return '';
	    	    	    		}else{
	    	    	    			return '<div style="text-align:right;">'+d.hhl+'</div> '
	    	    			    }
	    	    	    	}
	    				}
    				)
    				var header = yshead.concat(headerAppend);
    				tables = table.render({
				        elem: '#myTable'
				        ,id:'myTable'
				        ,cols: [header]
				    	,page: true
				        ,url: basePath + '/service/cxtj/fjsjcsgl'
				        ,where: {
				        	s_starnf:s_starnf,
				        	s_endnf:s_endnf,
				        	's_sign':s_sign
				        }
				        , done: function (res,curr,count) {
				            this.cols = []
				        }
				    });
    				
    	    	} else {
    	    		layer.msg(data.message)
    	    	}
    	    }
    	})
    }
    $(".ondc").click(function(){
    	var s_starnf = $("#s_starnf").val();
    	var s_endnf = $("#s_endnf").val();
    	var s_sign = layui.formSelects.value('s_sign', 'val');
    	if(s_starnf == '' || s_starnf == undefined || s_endnf == '' || s_endnf == undefined ){
    		layer.msg("请选择两个对比时间");
    		return;
    	}
    	$.ajax({
    		type: "GET",
    		url: basePath + '/service/exchangerate/getTwoByTwoFbDate/'+s_starnf+'/'+s_endnf,
    		async:false,
    	    dataType: "json",
    	    success: function(data){
    	    	if(data.code == 200){
    	    		window.open(basePath + '/service/cxtj/fjsjcsgl/down?s_starnf='+s_starnf+'&s_endnf='+s_endnf+'&s_signList='+s_sign);
    	    	} else {
    	    		layer.msg(data.message)
    	    	}
    	    }
    	})
    })
})
function HTMLDecode(text) {
    var temp = document.createElement("div");
    temp.innerHTML = text;
    var output = temp.innerText || temp.textContent;
    temp = null;
    return output;
} 	